//
//  SampleAppDelegate.m
//  HelloWorld
//
//  Created by Beomjun Kim on 09. 09. 18.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "SampleAppDelegate.h"
#import "RecommendedProductController.h"
#import "CategoryController.h"
#import "ProductController.h"
#import "RecentProductController.h"
#import "EventController.h"
#import	"BoardController.h"

@implementation SampleAppDelegate

/*
	메소드가 먼저 와야 한다.
 */


- (void)applicationDidFinishLaunching:(UIApplication *)application {	
	
	UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
	
	// Create the array of UIViewControllers
	NSMutableArray *controllers = [[NSMutableArray alloc] init];
	
	/*
	for (int i = 0; i < 5; i++) {
		// 생성할 때, 이름을 준다.
		BrightnessController *bControl = [[BrightnessController alloc] initWithTitle:[tabBarNames objectAtIndex:i]];
		
		UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:bControl];
		nav.navigationBar.barStyle = UIBarStyleBlackTranslucent;
		[controllers addObject:nav];
		[bControl release];
		[nav release];
	}
	 */
	
	// 네비게이션 컨트롤러 생성
	[self createNavigationControllers:controllers];
	
	// Create the toolbar and add the view controllers
	UITabBarController *tbarController = [[UITabBarController alloc] init];
	tbarController.viewControllers = controllers;
	tbarController.customizableViewControllers = controllers;
	tbarController.delegate = self;
	
	// Set up the window
	[window addSubview:tbarController.view];
	[window makeKeyAndVisible];
	
	[controllers release];
}

- (void) createNavigationControllers:(NSMutableArray *)controllers {
	
	// 탭바에 해당하는 이름을 준다.
	NSArray *tabBarNames = [NSArray arrayWithObjects:@"추천상품", @"인기상품", @"카테고리", @"최근상품", @"이벤트", @"게시판", nil];
	
	// 추천상품
	RecommendedProductController *bControl0 = [[RecommendedProductController alloc] initWithTitle:[tabBarNames objectAtIndex:0]];
	UINavigationController *nav0 = [[UINavigationController alloc] initWithRootViewController:bControl0];
	nav0.navigationBar.barStyle = UIBarStyleBlackTranslucent;
	[controllers addObject:nav0];
	[bControl0 release];
	[nav0 release];
	
	// 인기상품
	ProductController *bControl1 = [[ProductController alloc] initWithTitle:@"인기상품"
																	withUrl:@"http://www.haroohana.com/iphone/iphone_poppdt.php"];
	UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:bControl1];
	nav1.navigationBar.barStyle = UIBarStyleBlackTranslucent;
	[controllers addObject:nav1];
	[bControl1 release];
	[nav1 release];
	
	// 카테고리
	// CategoryController *bControl2 = [[CategoryController alloc] initWithTitle:@"카테고리"
	//																withUrl:@"http://192.168.123.109:9001/CategoryList.xml"];
	CategoryController *bControl2 = [[CategoryController alloc] initWithTitle:@"카테고리"
																	withUrl:@"http://www.haroohana.com/iphone/iphone_category.php"];
	UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:bControl2];
	nav2.navigationBar.barStyle = UIBarStyleBlackTranslucent;
	[controllers addObject:nav2];
	[bControl2 release];
	[nav2 release];
	
	/* 
	 기획변경에 의한 최근 상품 메뉴는 주석 처리
	 추후 변경의 소지가 있을 수 있으니 남겨 놓음
	 
	// 최근상품
	RecentProductController *bControl3 = [[RecentProductController alloc] initWithTitle:[tabBarNames objectAtIndex:3]];
	UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:bControl3];
	nav3.navigationBar.barStyle = UIBarStyleBlackTranslucent;
	[controllers addObject:nav3];
	[bControl3 release];
	[nav3 release];
	*/
	
	// 이벤트
	EventController *bControl4 = [[EventController alloc] initWithTitle:[tabBarNames objectAtIndex:4]];
	UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:bControl4];
	nav4.navigationBar.barStyle = UIBarStyleBlackTranslucent;
	[controllers addObject:nav4];
	[bControl4 release];
	[nav4 release];

	// 게시판
	BoardController *bControl5 = [[BoardController alloc] initWithTitle:@"게시판"
																withUrl:@"http://www.haroohana.com/iphone/iphone_board.php"];
	UINavigationController *nav5 = [[UINavigationController alloc] initWithRootViewController:bControl5];
	nav5.navigationBar.barStyle = UIBarStyleBlackTranslucent;
	[controllers addObject:nav5];
	[bControl5 release];
	[nav5 release];
	
}

@end
